﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.IntegerNumber
{
    class MathSqrtOfNUmber
    {
        static void Main(string[] args)
        {
            //Write a program that reads an integer number and calculates 
            //and prints its square root. If the number is invalid or negative, 
            //print "Invalid number". In all cases finally print "Good bye". Use try-catch-finally.

            Console.WriteLine("Insert an integer number");

            try
            {
                int number = int.Parse(Console.ReadLine());
                if (number < 0)
                {
                    throw new NegativeSystemException();
                }
                double MathSqrt = Math.Sqrt(number);
                Console.WriteLine("Math.Sqrt({0}) = {1}", number, MathSqrt);
            }
            catch (FormatException)
            {
                Console.WriteLine("Format Exception.Try again later!");
            }
            catch (NegativeSystemException)
            {
                Console.WriteLine("Negative number exception.Try again later!");
            }
            catch (OverflowException)
            {
                Console.WriteLine("Number is greater than its range.Try again later!");
            }
            finally
            {
                Console.WriteLine("Good Bye");
            }
        }
    }
}
class NegativeSystemException : Exception
{ 
}